<?php
/* 
 * EachGo电商网站 新媒体
 * www.eachgo.cn
 */
namespace Home\Model;
use Think\Model;
class ShareModel extends Model{
//    public function findById($shareId){
//        return $this->where("ID=".$shareId)->select();
//    }
    public function findById($userLotteryId){//通过userLotteryID查询一条数据
        return $this->where("userLotteryInfo_ID=".$userLotteryId)->select();
    }
    public function numberShared($userId){//查询用户的分享内容的id
        $sql="SELECT b.ID AS userLotterId
            FROM EachGo.`t_share` a JOIN EachGo.`t_user_lottery_info` b
            ON a.userLotteryInfo_ID=b.ID JOIN EachGo.`t_lottery_goods_info` c
            ON b.goods_ID=c.goods_ID
            WHERE b.lotteryNumber=c.luckyNumber
            AND b.lotteryTurn=c.lotteryTurn
            AND a.isShared=1
            AND a.user_ID=".$userId;
        return $this->query($sql);
    }
    /*添加分享*/
    public function addShare($data){//增加一条分享
        return $this->add($data);
    }
    /*删除分享*/
    public function deleteShare($id){
        return $this->where("ID=".$id)->delete();
    }
    /*查询所有分享*/
    public function queryAll($userId){
        $sql="SELECT a.ID AS shareId,b.ID AS userlotterId,a.isShared,a.imageURL,a.shareText,a.shareTime,a.title,b.lotteryTurn,c.goodsName
            FROM EachGo.`t_share` a JOIN EachGo.`t_user_lottery_info` b
            ON a.userLotteryInfo_ID = b.ID JOIN EachGo.`t_goods` c
            ON b.goods_ID=c.ID
            WHERE a.user_ID=".$userId." ORDER BY shareTime";
        return $this->query($sql);
    }
    /*更新分享*/
    public function update($data){
        return $this->where("userLotteryInfo_ID=".$data['userLotteryInfo_ID'])->save($data);
    }
}

